#ifndef PLAYER_H
#define PLAYER_H

#include <QGraphicsPixmapItem>
#include <QTimer>
#include <QObject>
#include<QGraphicsScene>


class Player : public QObject,public QGraphicsPixmapItem {

    Q_OBJECT
public:
    enum class State { Running, Jumping, Falling ,Crouching};

    explicit Player(QObject* parent = nullptr);

    void jump();
    void crouch();
    void setState(State newState);
    void updatePhysics();
    QTimer animationTimer;
public slots:
    void updateAnimation();
    void resetCrouch();
private:
    void loadFrames();
    void adjustPosition();
    State currentState = State::Running;
    int currentFrame = 0;
    QVector<QPixmap> runFrames;
    QPixmap jumpFrame;
    QPixmap fallFrame;
    QPixmap crouchFrame;
   //QVector<QPixmap> crouchFrames;


    // 物理参数
    qreal velocityY = 0;
    static constexpr qreal GRAVITY = 0.5;
    static constexpr qreal JUMP_FORCE = -17;
    bool isGrounded = true;
    bool isCrouching=false;
    QTimer crouchTimer;
};

#endif // PLAYER_H
